const { qiniuUpload, makeCrypto, trimSpace } = require('../lib/utils'),
        config = require('../config/config'),
        {adminInfo} = require('../config/config'),
        {addAdmin} = require('../service/admin');
class Admin {
    async testQiniu() {
        const qiniu = config.qiniu;
        try {
            const imgData = await qiniuUpload({
                url: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1605181531778&di=2b7524580da440cdabd494d411e456be&imgtype=0&src=http%3A%2F%2Fmedia-cdn.tripadvisor.com%2Fmedia%2Fphoto-s%2F01%2F3e%2F05%2F40%2Fthe-sandbar-that-links.jpg',
                bucket: qiniu.bucket.blogsimg.bucket_name,
                ak: qiniu.keys.ak,
                sk: qiniu.keys.sk,
                ext: '.jpg'
            })
           
        } catch (error) {
            console.log(error)
        }
    }
    async createAdmin(){
        adminInfo.password = makeCrypto(adminInfo.password)
        const result = await addAdmin(adminInfo);
        if(result){
            console.log(0);
        }else{
            console.log(1);
        }
    }
    async loginAction(ctx,next){
        const {username,password} = ctx.request.body;
        if(!username||!password){
            ctx.body = returnInfo(LOGIN.INVALID_OPERATION)
            return
        }
        if(trimSpace(username).length<=0){
            ctx.body = returnInfo(LOGIN.INVALID_USERNAME_LENGTH);
            return
        }
        if(trimSpace(password).length<=0){
            ctx.body = returnInfo(LOGIN.INVALID_PASSWORD_LENGTH)
        }
        const userInfo = {
            username:trimSpace(username),
            password:makeCrypto(trimSpace(password))
        }

    }
}      
module.exports = new Admin();